package com.nic.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nic.view.R;
import com.nic.view.adapter.ProjectMouldRecycleAdapter;
import com.nic.view.model.InputMouldBean;
import com.nic.view.model.MouldBean;
import com.nic.view.model.RadioMouldBean;
import com.nic.view.widget.RecycleViewDivide;

import java.util.ArrayList;
import java.util.List;


public class TestActivity extends Activity implements View.OnClickListener {

    RecyclerView recyclerView;
    ProjectMouldRecycleAdapter projectItemRecycleAdapter;
    TextView cancel;
    TextView submit;
    LinearLayout llBottom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        cancel = (TextView) findViewById(R.id.cancel);
        submit = (TextView) findViewById(R.id.submit);
        llBottom = (LinearLayout) findViewById(R.id.ll_bottom);
        cancel.setOnClickListener(this);
        submit.setOnClickListener(this);
        projectItemRecycleAdapter = new ProjectMouldRecycleAdapter(this);

        LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(new RecycleViewDivide(this, LinearLayoutManager.VERTICAL, 16));
        recyclerView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        recyclerView.setAdapter(projectItemRecycleAdapter);
        projectItemRecycleAdapter.setMouldBeanList(getMould());
    }

    private List<MouldBean> getMould() {
        List<MouldBean> list = new ArrayList<>();
        for (InputMouldBean inputMouldBean : setData()) {
            MouldBean m1 = new MouldBean();
            m1.setType(ProjectMouldRecycleAdapter.INPUT_MOULD);
            m1.setInputMouldBean(inputMouldBean);
            list.add(m1);
        }
        MouldBean m2 = new MouldBean();
        m2.setType(ProjectMouldRecycleAdapter.RADIO_MOULD);
        m2.setRadioMouldBean(getTestR());
        list.add(m2);
        MouldBean m3 = new MouldBean();
        m3.setType(ProjectMouldRecycleAdapter.TAKE_PHOTO_MOULD);
        list.add(m3);
        return list;
    }

    private RadioMouldBean getTestR() {
        RadioMouldBean radioMouldBean = new RadioMouldBean();
        radioMouldBean.setSubTitle("性别");
        List<RadioMouldBean.RadioMouldItemBean> list = new ArrayList<>();
        RadioMouldBean.RadioMouldItemBean item = new RadioMouldBean.RadioMouldItemBean();
        item.setSubTitle("男");
        list.add(item);
        RadioMouldBean.RadioMouldItemBean item1 = new RadioMouldBean.RadioMouldItemBean();
        item1.setSubTitle("女");
        list.add(item1);
        RadioMouldBean.RadioMouldItemBean item2 = new RadioMouldBean.RadioMouldItemBean();
        item2.setSubTitle("其他");
        list.add(item2);
        radioMouldBean.setList(list);
        return radioMouldBean;
    }

    public List<InputMouldBean> setData() {
        List<InputMouldBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            InputMouldBean a = new InputMouldBean();
            a.setSubTitle("第" + i + "项");
            a.setArrow(false);
            a.setHint("请输入");
            list.add(a);
        }
        InputMouldBean a = new InputMouldBean();
        a.setSubTitle("第" + 11 + "项");
        a.setArrow(true);
        a.setEditor(false);
        list.add(a);
        InputMouldBean a12 = new InputMouldBean();
        a12.setSubTitle("第" + 12 + "项");
        a12.setHint("请输入呀");
        list.add(a12);
        InputMouldBean a13 = new InputMouldBean();
        a13.setSubTitle("第" + 13 + "项");
        a13.setHint("请输入数字");
        a13.setUnit("吨");
        a13.setInputType(InputType.TYPE_CLASS_NUMBER);
        a13.setDigits("0123456789");
        a13.setMaxLength(10);
        list.add(a13);
        return list;
    }


    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.cancel) {
        } else if (i == R.id.submit) {
            projectItemRecycleAdapter.checkInputNull();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
